/****************************************************************************************************
* 
*   TITLE: Replication Data for "Policing in a Post-Conflict State: Evidence from Uganda"
*   AUTHOR: David A. Dow
*	DATE: July 18, 2021
*
****************************************************************************************************/


** Analysis Using Electoral Waves **

** Set directory
*cd "YOUR DIRECTORY"
cd "C:\Users\ddow1\Dropbox\Uganda Policing CPS\Replication\Data"
use ug_police_waves_rep.dta, clear

** set control variables for infrastructure models
global controls zl5log1_v4cal_sol_panel zdistance_capital_km zl5log_popdensity_panel Zbanyanshare_max military_bases zlog_std_altitude zcases2003_popshare_per1000 zl5police_infra_totalstock i.region i.wave

// Table 2
// 1) stock; 2) sum; 3) sum + elections; 4) elections squared 5) sum x elections interaction
logit p_infrastructure_electoralwaves zl5ucdp_stock123 $controls i.region i.wave, cluster(countyid02)
outreg2 using Table_2.doc, title(Table 2: Police Infrastructure Construction) label addtext(Wave Fixed Effects, Yes, Region Dummies, Yes) ctitle(" ") bdec(3) sdec(2) replace

logit p_infrastructure_electoralwaves zl5ucdp_sum123 $controls, cluster(countyid02)
outreg2 using Table_2.doc, title(Table 2: Police Infrastructure Construction) label addtext(Wave Fixed Effects, Yes, Region Dummies, Yes) ctitle(" ") bdec(3) sdec(2) append

logit p_infrastructure_electoralwaves c.zl5ucdp_sum123 c.zlag_mshare $controls, cluster(countyid02)
outreg2 using Table_2.doc, title(Table 2: Police Infrastructure Construction) label addtext(Wave Fixed Effects, Yes, Region Dummies, Yes) ctitle(" ") bdec(3) sdec(2) append

logit p_infrastructure_electoralwaves c.zl5ucdp_sum123 c.zlag_mshare##c.zlag_mshare $controls, cluster(countyid02)
outreg2 using Table_2.doc, title(Table 2: Police Infrastructure Construction) label addtext(Wave Fixed Effects, Yes, Region Dummies, Yes) ctitle(" ") bdec(3) sdec(2) append

logit p_infrastructure_electoralwaves c.zl5ucdp_sum123##c.zlag_mshare $controls, cluster(countyid02)
outreg2 using Table_2.doc, title(Table 2: Police Infrastructure Construction) label addtext(Wave Fixed Effects, Yes, Region Dummies, Yes) ctitle(" ") bdec(3) sdec(2) append

** Figure 1. Plotting interaction effects of conflict and vote share
logit p_infrastructure_electoralwaves c.zl5ucdp_sum123##c.lag_mshare $controls, cluster(countyid02)
margins, dydx(zl5ucdp_sum123) at(lag_mshare=(0(.01)1))
marginsplot, title("Average Marginal Effect of Conflict") xtitle("Incumbent Vote Share") recast(line) recastci(rarea) yline(0, lpattern(dash) lcolor(red)) scheme(s1mono) ylabel(, angle(0) nogrid)
graph export ame_conflict.png, replace

logit p_infrastructure_electoralwaves c.l5total_ucdp_conflict_sum123##c.zlag_mshare $controls, cluster(countyid02)
margins, dydx(zlag_mshare) at(l5total_ucdp_conflict_sum123=(0(1)15))
marginsplot, title("Average Marginal Effect of Vote Share") xtitle("Conflict Events - Election Year") recast(line) recastci(rarea) yline(0, lpattern(dash) lcolor(red)) scheme(s1mono) ylabel(, angle(0) nogrid)
graph export ame_vote.png, replace


****************************************************************************
*** Table 4. Effect of police infrastructure building on voting outcomes ***
****************************************************************************

*** Fixed effects models: 1) support for Museveni and 2) voter turnout
xtset countyid02 wave

xtreg mshare_county pstation_count_electoral_waves ppost_count_electoral_waves lag_mshare zl5ucdp_sum123 zl5log1_v4cal_sol_panel zl5log_popdensity_panel zl5police_infra_totalstock wave, fe cluster(countyid02)
outreg2 using Table_4c.doc, label addtext(County Fixed Effects, Yes, Model, OLS) ctitle(" ") bdec(3) sdec(2) replace

xtreg turnout_panel pstation_count_electoral_waves ppost_count_electoral_waves lag_mshare zl5ucdp_sum123 zl5log1_v4cal_sol_panel zl5log_popdensity_panel zl5police_infra_totalstock wave, fe cluster(countyid02)
outreg2 using Table_4c.doc, title(Police Infrastructure and Voting Outcomes) label addtext(County Fixed Effects, Yes, Model, OLS) ctitle(" ") bdec(3) sdec(2) append

*********************************************************************
*****	Appendix Tables with Infrastructure Outcomes (A2 - A11) *****
*********************************************************************

// A2. Logit models robustness - police infrastructure controls for missing construction dates
// waves 96-00, 01-05, 06-10
logit p_infrastructure_electoralwaves zl5ucdp_stock123 $controls pstation_missing_const_sum ppost_all_nodate_sum, cluster(countyid02)
outreg2 using Table_A2.doc, label addtext(Wave Fixed Effects, Yes, Region Dummies, Yes) ctitle(" ") bdec(3) sdec(2) replace

logit p_infrastructure_electoralwaves zl5ucdp_sum123 $controls pstation_missing_const_sum ppost_all_nodate_sum i.region i.wave, cluster(countyid02)
outreg2 using Table_A2.doc, label addtext(Wave Fixed Effects, Yes, Region Dummies, Yes) ctitle(" ") bdec(3) sdec(2) append

logit p_infrastructure_electoralwaves c.zl5ucdp_sum123 c.zlag_mshare $controls pstation_missing_const_sum ppost_all_nodate_sum, cluster(countyid02)
outreg2 using Table_A2.doc, label addtext(Wave Fixed Effects, Yes, Region Dummies, Yes) ctitle(" ") bdec(3) sdec(2) append

logit p_infrastructure_electoralwaves c.zl5ucdp_sum123 c.zlag_mshare##c.zlag_mshare $controls pstation_missing_const_sum ppost_all_nodate_sum, cluster(countyid02)
outreg2 using Table_A2.doc, label addtext(Wave Fixed Effects, Yes, Region Dummies, Yes) ctitle(" ") bdec(3) sdec(2) append

logit p_infrastructure_electoralwaves c.zl5ucdp_sum123##c.zlag_mshare $controls pstation_missing_const_sum ppost_all_nodate_sum, cluster(countyid02)
outreg2 using Table_A2.doc, title(Table A2: Police Infrastructure Construction - Robustness for Missing Construction Dates) label addtext(Wave Fixed Effects, Yes, Region Dummies, Yes) ctitle(" ") bdec(3) sdec(2) append

// logit models robustness - police infrastructure controls for missing construction dates
// A3. only for post 2006 results
logit p_infrastructure_electoralwaves zl5ucdp_stock123 $controls pstation_missing_const_sum ppost_all_nodate_sum if wave>2, cluster(countyid02)
outreg2 using Table_A3.doc, label addtext(Election Wave Dummies, No, Region Dummies, Yes) ctitle(" ") bdec(3) sdec(2) replace

logit p_infrastructure_electoralwaves zl5ucdp_sum123 $controls pstation_missing_const_sum ppost_all_nodate_sum if wave>2, cluster(countyid02)
outreg2 using Table_A3.doc, label addtext(Election Wave Dummies, No, Region Dummies, Yes) ctitle(" ") bdec(3) sdec(2) append

logit p_infrastructure_electoralwaves c.zl5ucdp_sum123 c.zlag_mshare $controls pstation_missing_const_sum ppost_all_nodate_sum if wave>2, cluster(countyid02)
outreg2 using Table_A3.doc, label addtext(Election Wave Dummies, No, Region Dummies, Yes) ctitle(" ") bdec(3) sdec(2) append

logit p_infrastructure_electoralwaves c.zl5ucdp_sum123 c.zlag_mshare##c.zlag_mshare $controls pstation_missing_const_sum ppost_all_nodate_sum if wave>2, cluster(countyid02)
outreg2 using Table_A3.doc, label addtext(Election Wave Dummies, No, Region Dummies, Yes) ctitle(" ") bdec(3) sdec(2) append

logit p_infrastructure_electoralwaves c.zl5ucdp_sum123##c.zlag_mshare $controls pstation_missing_const_sum ppost_all_nodate_sum if wave>2, cluster(countyid02)
outreg2 using Table_A3.doc, title(Table A3: Police Infrastructure Construction - 2006-2010 Wave Only) label addtext(Election Wave Dummies, No, Region Dummies, Yes) ctitle(" ") bdec(3) sdec(2) append


// A4. random-effects models
xtreg p_infrastructure_electoralwaves zl5ucdp_stock123 $controls pstation_missing_const_sum ppost_all_nodate_sum, cluster(countyid02)
outreg2 using Table_A4.doc, label addtext(Election Wave Dummies, Yes, Region Dummies, Yes) ctitle(" ") bdec(3) sdec(2) replace

xtreg p_infrastructure_electoralwaves zl5ucdp_sum123 $controls pstation_missing_const_sum ppost_all_nodate_sum, cluster(countyid02)
outreg2 using Table_A4.doc, label addtext(Election Wave Dummies, Yes, Region Dummies, Yes) ctitle(" ") bdec(3) sdec(2) append

xtreg p_infrastructure_electoralwaves c.zl5ucdp_sum123 c.zlag_mshare $controls pstation_missing_const_sum ppost_all_nodate_sum, cluster(countyid02)
outreg2 using Table_A4.doc, label addtext(Election Wave Dummies, Yes, Region Dummies, Yes) ctitle(" ") bdec(3) sdec(2) append

xtreg p_infrastructure_electoralwaves c.zl5ucdp_sum123 c.zlag_mshare##c.zlag_mshare $controls pstation_missing_const_sum ppost_all_nodate_sum, cluster(countyid02)
outreg2 using Table_A4.doc, label addtext(Election Wave Dummies, Yes, Region Dummies, Yes) ctitle(" ") bdec(3) sdec(2) append

xtreg p_infrastructure_electoralwaves c.zl5ucdp_sum123##c.zlag_mshare $controls pstation_missing_const_sum ppost_all_nodate_sum, cluster(countyid02)
outreg2 using Table_A4.doc, title(Table A4: Police Infrastructure Construction (Random Effects Models)) label addtext(Election Wave Dummies, Yes, Region Dummies, Yes) ctitle(" ") bdec(3) sdec(2) append


// A5. Negative binomial models
nbreg polinfra_count_electoral_waves zl5ucdp_stock123 $controls pstation_missing_const_sum ppost_all_nodate_sum, cluster(countyid02)
outreg using Table_A5, title(Table A5: Police Infrastructure Construction Counts (Negative Binomial Models)) varlabels starlevels(10 5 1) addrows("Wave Fixed Effects", "Yes"\"Region Dummies", "Yes") coljust(l;c) se replace

nbreg polinfra_count_electoral_waves zl5ucdp_sum123 $controls pstation_missing_const_sum ppost_all_nodate_sum, cluster(countyid02)
outreg using Table_A5, title(Table A5: Police Infrastructure Construction Counts (Negative Binomial Models)) varlabels starlevels(10 5 1) addrows("Wave Fixed Effects", "Yes"\"Region Dummies", "Yes") coljust(l;c) se merge

nbreg polinfra_count_electoral_waves c.zl5ucdp_sum123 c.zlag_mshare $controls pstation_missing_const_sum ppost_all_nodate_sum, cluster(countyid02)
outreg using Table_A5, title(Table A5: Police Infrastructure Construction Counts (Negative Binomial Models)) varlabels starlevels(10 5 1) addrows("Wave Fixed Effects", "Yes"\"Region Dummies", "Yes") coljust(l;c) se merge

nbreg polinfra_count_electoral_waves c.zl5ucdp_sum123 c.zlag_mshare##c.zlag_mshare $controls pstation_missing_const_sum ppost_all_nodate_sum, cluster(countyid02)
outreg using Table_A5, title(Table A5: Police Infrastructure Construction Counts (Negative Binomial Models)) varlabels starlevels(10 5 1) addrows("Wave Fixed Effects", "Yes"\"Region Dummies", "Yes") coljust(l;c) se merge

nbreg polinfra_count_electoral_waves c.zl5ucdp_sum123##c.zlag_mshare $controls pstation_missing_const_sum ppost_all_nodate_sum, cluster(countyid02)
outreg using Table_A5, title(Table A5: Police Infrastructure Construction Counts (Negative Binomial Models)) varlabels starlevels(10 5 1) addrows("Wave Fixed Effects", "Yes"\"Region Dummies", "Yes") coljust(l;c) se merge

// spatial models for electoral waves and police instrastructure
// A6. Spatial Logit models 

gen zlag_mshareXzlag_mshare = zlag_mshare*zlag_mshare
gen zl5ucdp_sum123Xzlag_mshare = zl5ucdp_sum123*zlag_mshare

do "C:\Users\ddow1\Dropbox\DevLab DD\Uganda Policing CPS\Replication\Code\xgmlt.ado"
gen const=1
gen cutoff1=4
gen cutoff2=4

** Note: Spatial models below are output into separate documents

xgmlt longitude_section latitude_section cutoff1 cutoff2 p_infrastructure_electoralwaves const zl5ucdp_stock123 zl5log1_v4cal_sol_panel zdistance_capital_km zl5log_popdensity_panel Zbanyanshare_max military_bases zlog_std_altitude zcases2003_popshare_per1000 zl5police_infra_totalstock pstation_missing_const_sum ppost_all_nodate_sum Nregion1 Nregion2 Nregion3 wave2 wave3, xreg(17) coord(2)
outreg using Table_A6_M1, title(Table A6: Police Infrastructure Construction (Spatial Logits)) starlevels(10 5 1) addrows("Wave Fixed Effects", "Yes"\"Region Dummies", "Yes") coljust(l;c) ctitle(" ", "1") rtitles("Constant" \ " " \ "Conflict Stock" \ " " \ "Night Lights Sum" \ " " \ "Distance to Capital" \ " " \ "Population Density" \ " " \ "Bankyankole Share" \ " " \ "Military Bases" \ " " \ "Altitude Deviation" \ " " \ "Crimes Reported (2003)" \ " " \ "Infrastructure Stock (t-5)" \ " " \ "Police Stations Missing" \ " " \ "Police Posts Missing" \ " " \ "Central Region" \ " " \ "Eastern Region" \ " " \ "Northern Region" \ " " \ "Wave 2" \ " " \ "Wave 3") se replace

xgmlt longitude_section latitude_section cutoff1 cutoff2 p_infrastructure_electoralwaves const zl5ucdp_sum123 zl5log1_v4cal_sol_panel zdistance_capital_km zl5log_popdensity_panel Zbanyanshare_max military_bases zlog_std_altitude zcases2003_popshare_per1000 zl5police_infra_totalstock pstation_missing_const_sum ppost_all_nodate_sum  Nregion1 Nregion2 Nregion3 wave2 wave3, xreg(17) coord(2)
outreg using Table_A6_M2, title(Table A6: Police Infrastructure Construction (Spatial Logits)) starlevels(10 5 1) addrows("Wave Fixed Effects", "Yes"\"Region Dummies", "Yes") coljust(l;c) ctitle(" ", "2") rtitles("Constant" \ " " \ "Conflict Count (Election year, t-5)" \ " " \ "Night Lights Sum" \ " " \ "Distance to Capital" \ " " \ "Population Density" \ " " \ "Bankyankole Share" \ " " \ "Military Bases" \ " " \ "Altitude Deviation" \ " " \ "Crimes Reported (2003)" \ " " \ "Infrastructure Stock (t-5)" \ " " \ "Police Stations Missing" \ " " \ "Police Posts Missing" \ " " \ "Central Region" \ " " \ "Eastern Region" \ " " \ "Northern Region" \ " " \ "Wave 2" \ " " \ "Wave 3") se replace

xgmlt longitude_section latitude_section cutoff1 cutoff2 p_infrastructure_electoralwaves const zl5ucdp_sum123 zlag_mshare zl5log1_v4cal_sol_panel zdistance_capital_km zl5log_popdensity_panel Zbanyanshare_max military_bases zlog_std_altitude zcases2003_popshare_per1000 zl5police_infra_totalstock pstation_missing_const_sum ppost_all_nodate_sum  Nregion1 Nregion2 Nregion3 wave2 wave3, xreg(18) coord(2)
outreg using Table_A6_M3, title(Table A6: Police Infrastructure Construction (Spatial Logits)) starlevels(10 5 1) addrows("Wave Fixed Effects", "Yes"\"Region Dummies", "Yes") coljust(l;c) ctitle(" ", "3") rtitles("Constant" \ " " \ "Conflict Count (Election year, t-5)" \ "" \ "Incumbent Vote Share" \ " " \ "Night Lights Sum" \ " " \ "Distance to Capital" \ " " \ "Population Density" \ " " \ "Bankyankole Share" \ " " \ "Military Bases" \ " " \ "Altitude Deviation" \ " " \ "Crimes Reported (2003)" \ " " \ "Infrastructure Stock (t-5)" \ " " \ "Police Stations Missing" \ " " \ "Police Posts Missing" \ " " \ "Central Region" \ " " \ "Eastern Region" \ " " \ "Northern Region" \ " " \ "Wave 2" \ " " \ "Wave 3") se replace

xgmlt longitude_section latitude_section cutoff1 cutoff2 p_infrastructure_electoralwaves const zl5ucdp_sum123 zlag_mshare zlag_mshareXzlag_mshare zl5log1_v4cal_sol_panel zdistance_capital_km zl5log_popdensity_panel Zbanyanshare_max military_bases zlog_std_altitude zcases2003_popshare_per1000 zl5police_infra_totalstock pstation_missing_const_sum ppost_all_nodate_sum  Nregion1 Nregion2 Nregion3 wave2 wave3, xreg(19) coord(2)
outreg using Table_A6_M4, title(Table A6: Police Infrastructure Construction (Spatial Logits)) starlevels(10 5 1) addrows("Wave Fixed Effects", "Yes"\"Region Dummies", "Yes") coljust(l;c) ctitle(" ", "4") rtitles("Constant" \ " " \ "Conflict Count (Election year, t-5)" \ "" \ "Incumbent Vote Share" \ " " \ "Incumbent Share Squared" \ " " \ "Night Lights Sum" \ " " \ "Distance to Capital" \ " " \ "Population Density" \ " " \ "Bankyankole Share" \ " " \ "Military Bases" \ " " \ "Altitude Deviation" \ " " \ "Crimes Reported (2003)" \ " " \ "Infrastructure Stock (t-5)" \ " " \ "Police Stations Missing" \ " " \ "Police Posts Missing" \ " " \ "Central Region" \ " " \ "Eastern Region" \ " " \ "Northern Region" \ " " \ "Wave 2" \ " " \ "Wave 3") se replace

xgmlt longitude_section latitude_section cutoff1 cutoff2 p_infrastructure_electoralwaves const zl5ucdp_sum123 zlag_mshare zl5ucdp_sum123Xzlag_mshare zl5log1_v4cal_sol_panel zdistance_capital_km zl5log_popdensity_panel Zbanyanshare_max military_bases zlog_std_altitude zcases2003_popshare_per1000 zl5police_infra_totalstock pstation_missing_const_sum ppost_all_nodate_sum  Nregion1 Nregion2 Nregion3 wave2 wave3, xreg(19) coord(2)
outreg using Table_A6_M5, title(Table A6: Police Infrastructure Construction (Spatial Logits)) starlevels(10 5 1) addrows("Wave Fixed Effects", "Yes"\"Region Dummies", "Yes") coljust(l;c) ctitle(" ", "4") rtitles("Constant" \ " " \ "Conflict Count (Election year, t-5)" \ "" \ "Incumbent Vote Share" \ " " \ "Incumbent Share X Conflict Count" \ " " \ "Night Lights Sum" \ " " \ "Distance to Capital" \ " " \ "Population Density" \ " " \ "Bankyankole Share" \ " " \ "Military Bases" \ " " \ "Altitude Deviation" \ " " \ "Crimes Reported (2003)" \ " " \ "Infrastructure Stock (t-5)" \ " " \ "Police Stations Missing" \ " " \ "Police Posts Missing" \ " " \ "Central Region" \ " " \ "Eastern Region" \ " " \ "Northern Region" \ " " \ "Wave 2" \ " " \ "Wave 3") se replace


// A7. Spatial Autogregessive Models
ssc install xsmle

use county_ug_weights.dta, clear
spmat dta W m*, normalize(row)
spmat summarize W

use ug_police_waves_rep_final.dta, clear 
spmat summarize W
xtset spatial_id wave
tsset spatial_id wave

xsmle p_infrastructure_electoralwaves zl5ucdp_stock123 $controls pstation_missing_const_sum ppost_all_nodate_sum, wmat(W) model(sar) vce(cluster spatial_id)
outreg using Table_A7, title(Table A7: Police Infrastructure Construction (Spatial Autoregressive Models)) varlabels starlevels(10 5 1) addrows("Wave Fixed Effects", "Yes"\"Region Dummies", "Yes") coljust(l;c) se replace

xsmle p_infrastructure_electoralwaves zl5ucdp_sum123 $controls pstation_missing_const_sum ppost_all_nodate_sum, wmat(W) model(sar) vce(cluster spatial_id)
outreg using Table_A7, title(Table A7: Police Infrastructure Construction (Spatial Autoregressive Models)) varlabels starlevels(10 5 1) addrows("Wave Fixed Effects", "Yes"\"Region Dummies", "Yes") coljust(l;c) se merge

xsmle p_infrastructure_electoralwaves c.zl5ucdp_sum123 c.zlag_mshare $controls pstation_missing_const_sum ppost_all_nodate_sum, wmat(W) model(sar) vce(cluster spatial_id)
outreg using Table_A7, title(Table A7: Police Infrastructure Construction (Spatial Autoregressive Models)) varlabels starlevels(10 5 1) addrows("Wave Fixed Effects", "Yes"\"Region Dummies", "Yes") coljust(l;c) se merge

xsmle p_infrastructure_electoralwaves c.zl5ucdp_sum123 c.zlag_mshare##c.zlag_mshare $controls pstation_missing_const_sum ppost_all_nodate_sum, wmat(W) model(sar) vce(cluster spatial_id)
outreg using Table_A7, title(Table A7: Police Infrastructure Construction (Spatial Autoregressive Models)) varlabels starlevels(10 5 1) addrows("Wave Fixed Effects", "Yes"\"Region Dummies", "Yes") coljust(l;c) se merge

xsmle p_infrastructure_electoralwaves c.zl5ucdp_sum123##c.zlag_mshare $controls pstation_missing_const_sum ppost_all_nodate_sum, wmat(W) model(sar) vce(cluster spatial_id)
outreg using Table_A7, title(Table A7: Police Infrastructure Construction (Spatial Autoregressive Models)) varlabels starlevels(10 5 1) addrows("Wave Fixed Effects", "Yes"\"Region Dummies", "Yes") coljust(l;c) se merge


// A8. Main models with police stations only
sort countyid02 wave

logit pstation_electoral_waves zl5ucdp_stock123 $controls pstation_missing_const_sum ppost_all_nodate_sum, cluster(countyid02)
outreg2 using Table_A8.doc, label addtext(Election Wave Dummies, Yes, Region Dummies, Yes) ctitle(" ") bdec(3) sdec(2) replace

logit pstation_electoral_waves zl5ucdp_sum123 $controls pstation_missing_const_sum ppost_all_nodate_sum, cluster(countyid02)
outreg2 using Table_A8.doc, label addtext(Election Wave Dummies, Yes, Region Dummies, Yes) ctitle(" ") bdec(3) sdec(2) append

logit pstation_electoral_waves c.zl5ucdp_sum123 c.zlag_mshare $controls pstation_missing_const_sum ppost_all_nodate_sum, cluster(countyid02)
outreg2 using Table_A8.doc, label addtext(Election Wave Dummies, Yes, Region Dummies, Yes) ctitle(" ") bdec(3) sdec(2) append

logit pstation_electoral_waves c.zl5ucdp_sum123 c.zlag_mshare##c.zlag_mshare $controls pstation_missing_const_sum ppost_all_nodate_sum, cluster(countyid02)
outreg2 using Table_A8.doc, label addtext(Election Wave Dummies, Yes, Region Dummies, Yes) ctitle(" ") bdec(3) sdec(2) append

logit pstation_electoral_waves c.zl5ucdp_sum123##c.zlag_mshare $controls pstation_missing_const_sum ppost_all_nodate_sum, cluster(countyid02)
outreg2 using Table_A8.doc, title(Table A8: Police Station Only Construction) label addtext(Election Wave Dummies, Yes, Region Dummies, Yes) ctitle(" ") bdec(3) sdec(2) append


// A9. Main models police posts only

logit ppost_electoral_waves zl5ucdp_stock123 $controls pstation_missing_const_sum ppost_all_nodate_sum, cluster(countyid02)
outreg2 using Table_A9.doc, label addtext(Election Wave Dummies, Yes, Region Dummies, Yes) ctitle(" ") bdec(3) sdec(2) replace

logit ppost_electoral_waves zl5ucdp_sum123 $controls pstation_missing_const_sum ppost_all_nodate_sum, cluster(countyid02)
outreg2 using Table_A9.doc, label addtext(Election Wave Dummies, Yes, Region Dummies, Yes) ctitle(" ") bdec(3) sdec(2) append

logit ppost_electoral_waves c.zl5ucdp_sum123 c.zlag_mshare $controls pstation_missing_const_sum ppost_all_nodate_sum, cluster(countyid02)
outreg2 using Table_A9.doc, label addtext(Election Wave Dummies, Yes, Region Dummies, Yes) ctitle(" ") bdec(3) sdec(2) append

logit ppost_electoral_waves c.zl5ucdp_sum123 c.zlag_mshare##c.zlag_mshare $controls pstation_missing_const_sum ppost_all_nodate_sum, cluster(countyid02)
outreg2 using Table_A9.doc, label addtext(Election Wave Dummies, Yes, Region Dummies, Yes) ctitle(" ") bdec(3) sdec(2) append

logit ppost_electoral_waves c.zl5ucdp_sum123##c.zlag_mshare $controls pstation_missing_const_sum ppost_all_nodate_sum, cluster(countyid02)
outreg2 using Table_A9.doc, title(Table A9: Police Post Only Construction) label addtext(Election Wave Dummies, Yes, Region Dummies, Yes) ctitle(" ") bdec(3) sdec(2) append


*************************************************************************
*****	Tables A10 and A11. Robustness checks using annual data		*****
*************************************************************************
use ug_police_annual_rep.dta, clear

** Table A10. Logit models with 1 year lag
logit police_infrastructure_dummy l1.ztotal_ucdp_stock123 l1.v4cal_sol_panel zdistance_capital_km l1.log_popdensity_panel zbanyanshare military_bases zstd_altitude_ln cases_reported2003_popsharewt l1.p_infra_stock pstation_missing_const_sum ppost_all_nodate_sum i.region i.year, cluster(countyid02)
outreg2 using Table_A10.xls, label addtext(Year Fixed Effects, Yes, Region Dummies, Yes) ctitle(" ") bdec(3) sdec(2) drop(i.year) replace

logit police_infrastructure_dummy l1.ztotal_ucdp_conflict_sum123 l1.v4cal_sol_panel zdistance_capital_km l1.log_popdensity_panel zbanyanshare military_bases zstd_altitude_ln cases_reported2003_popsharewt l1.p_infra_stock pstation_missing_const_sum ppost_all_nodate_sum i.region i.year, cluster(countyid02)
outreg2 using Table_A10.xls, label addtext(Year Fixed Effects, Yes, Region Dummies, Yes) ctitle(" ") bdec(3) sdec(2) drop(i.year) append

logit police_infrastructure_dummy l1.ztotal_ucdp_conflict_sum123 zmshare_panel_nolag l1.v4cal_sol_panel zdistance_capital_km l1.log_popdensity_panel zbanyanshare military_bases zstd_altitude_ln cases_reported2003_popsharewt l1.p_infra_stock pstation_missing_const_sum ppost_all_nodate_sum i.region i.year, cluster(countyid02)
outreg2 using Table_A10.xls, label addtext(Year Fixed Effects, Yes, Region Dummies, Yes) ctitle(" ") bdec(3) sdec(2) drop(i.year) append

logit police_infrastructure_dummy l1.ztotal_ucdp_conflict_sum123 c.zmshare_panel_nolag##c.zmshare_panel_nolag l1.v4cal_sol_panel zdistance_capital_km l1.log_popdensity_panel zbanyanshare military_bases zstd_altitude_ln cases_reported2003_popsharewt l1.p_infra_stock pstation_missing_const_sum ppost_all_nodate_sum i.region i.year, cluster(countyid02)
outreg2 using Table_A10.xls, label addtext(Year Fixed Effects, Yes, Region Dummies, Yes) ctitle(" ") bdec(3) sdec(2) drop(i.year) append

logit police_infrastructure_dummy c.l1.ztotal_ucdp_conflict_sum123##c.zmshare_panel_nolag l1.v4cal_sol_panel zdistance_capital_km l1.log_popdensity_panel zbanyanshare military_bases zstd_altitude_ln cases_reported2003_popsharewt l1.p_infra_stock pstation_missing_const_sum ppost_all_nodate_sum i.region i.year, cluster(countyid02)
outreg2 using Table_A10.xls, label title(Table A10: Annual Changes in Police Infrastructure Construction) addtext(Year Fixed Effects, Yes, Region Dummies, Yes) ctitle(" ") bdec(3) sdec(2) drop(i.year) append

** Table A11. Logit Models 1 year lag with added protests/riots stock
logit police_infrastructure_dummy l1.zprotest_riot_stock12  l1.ztotal_ucdp_stock123 l1.v4cal_sol_panel zdistance_capital_km l1.log_popdensity_panel zbanyanshare military_bases zstd_altitude_ln cases_reported2003_popsharewt l1.p_infra_stock pstation_missing_const_sum ppost_all_nodate_sum i.region i.year, cluster(countyid02)
outreg2 using Table_A11.xls, label addtext(Year Fixed Effects, Yes, Region Dummies, Yes) ctitle(" ") bdec(3) sdec(2) drop(i.year) replace

logit police_infrastructure_dummy l1.zprotest_riot_stock12 l1.ztotal_ucdp_conflict_sum123 l1.v4cal_sol_panel zdistance_capital_km l1.log_popdensity_panel zbanyanshare military_bases zstd_altitude_ln cases_reported2003_popsharewt l1.p_infra_stock pstation_missing_const_sum ppost_all_nodate_sum i.region i.year, cluster(countyid02)
outreg2 using Table_A11.xls, label addtext(Year Fixed Effects, Yes, Region Dummies, Yes) ctitle(" ") bdec(3) sdec(2) drop(i.year) append

logit police_infrastructure_dummy l1.zprotest_riot_stock12 l1.ztotal_ucdp_conflict_sum123 zmshare_panel_nolag l1.v4cal_sol_panel zdistance_capital_km l1.log_popdensity_panel zbanyanshare military_bases zstd_altitude_ln cases_reported2003_popsharewt l1.p_infra_stock pstation_missing_const_sum ppost_all_nodate_sum i.region i.year, cluster(countyid02)
outreg2 using Table_A11.xls, label addtext(Year Fixed Effects, Yes, Region Dummies, Yes) ctitle(" ") bdec(3) sdec(2) drop(i.year) append

logit police_infrastructure_dummy l1.zprotest_riot_stock12 l1.ztotal_ucdp_conflict_sum123 c.zmshare_panel_nolag##c.zmshare_panel_nolag l1.v4cal_sol_panel zdistance_capital_km l1.log_popdensity_panel zbanyanshare military_bases zstd_altitude_ln cases_reported2003_popsharewt l1.p_infra_stock pstation_missing_const_sum ppost_all_nodate_sum i.region i.year, cluster(countyid02)
outreg2 using Table_A11.xls, label addtext(Year Fixed Effects, Yes, Region Dummies, Yes) ctitle(" ") bdec(3) sdec(2) drop(i.year) append

logit police_infrastructure_dummy l1.zprotest_riot_stock12 c.l1.ztotal_ucdp_conflict_sum123##c.zmshare_panel_nolag l1.v4cal_sol_panel zdistance_capital_km l1.log_popdensity_panel zbanyanshare military_bases zstd_altitude_ln cases_reported2003_popsharewt l1.p_infra_stock pstation_missing_const_sum ppost_all_nodate_sum i.region i.year, cluster(countyid02)
outreg2 using Table_A11.xls, label title(Table A11: Annual Changes in Construction (controlling for protests/riots)) addtext(Year Fixed Effects, Yes, Region Dummies, Yes) ctitle(" ") bdec(3) sdec(2) drop(i.year) append


**************************************************
*****	AFROBAROMETER MODELS & FIGURES		******
**************************************************

use ug_ab_r2r6_rep.dta, clear

** set control variables
global controls_ab gender age edu living_conditions urbrur i.round_n

** Table 3: Police Facility Proximity and Partisanship - HLM Regressions
** Multilevel models - mixed effects models

mixed trust_police party_id_opp enum_police $controls_ab || townvill: enum_police urbrur, vce(cluster townvill)
estimates store m1
mixed trust_police party_id_opp##enum_police $controls_ab  || townvill: enum_police urbrur, vce(cluster townvill)
estimates store m2
mixed police_bribed_recode party_id_opp enum_police $controls_ab  || townvill: enum_police urbrur, vce(cluster townvill)
estimates store m3
mixed police_bribed_recode party_id_opp##enum_police $controls_ab  || townvill: enum_police urbrur, vce(cluster townvill)
estimates store m4
mixed police_service_recode party_id_opp enum_police $controls_ab  || townvill: enum_police urbrur, vce(cluster townvill)
estimates store m5
mixed police_service_recode party_id_opp##enum_police $controls_ab  || townvill: enum_police urbrur, vce(cluster townvill)
estimates store m6

esttab m1 m2 m3 m4 m5 m6 using Table_3.rtf, label mtitle("AB1" "AB2" "AB3" "AB4" "AB5" "AB6") title(Police Facility Proximity and Partisanship - HLM Regressions) star(* 0.10 ** 0.05 *** 0.01) drop(*round_n) b(3) se compress replace

** Figure 2. Marginal Interaction Effects
mixed trust_police party_id_opp##enum_police $controls_ab || townvill: enum_police urbrur, vce(cluster townvill)
margins, dydx(enum_police) over(party_id_opp)
marginsplot, recast(scatter) title(Trust in Police)
graph save trust.gph, replace

mixed police_bribed_recode party_id_opp##enum_police $controls_ab || townvill: enum_police urbrur, vce(cluster townvill)
margins, dydx(enum_police) over(party_id_opp)
marginsplot, recast(scatter) title(Police Bribery)
graph save bribery.gph, replace

mixed police_service_recode party_id_opp##enum_police $controls_ab || townvill: enum_police urbrur, vce(cluster townvill)
margins, dydx(enum_police) over(party_id_opp)
marginsplot, recast(scatter) title(Police Service)
graph save service.gph, replace

graph combine trust.gph bribery.gph service.gph, ycommon xcommon rows(1)


** Table A12. Police Facility Proximity and Partisanship - Robustness Checks w/ alternative DV coding

mixed police_bribed_drop party_id_opp enum_police $controls_ab || townvill: enum_police urbrur, vce(cluster townvill)
estimates store r1
mixed police_bribed_drop party_id_opp##enum_police $controls_ab || townvill: enum_police urbrur, vce(cluster townvill)
estimates store r2
mixed police_service_drop party_id_opp enum_police $controls_ab || townvill: enum_police urbrur, vce(cluster townvill)
estimates store r3
mixed police_service_drop party_id_opp##enum_police $controls_ab || townvill: enum_police urbrur, vce(cluster townvill)
estimates store r4

esttab r1 r2 r3 r4 using Table_A12.rtf, label mtitle("AB1" "AB2" "AB3" "AB4" "AB5" "AB6") title(Table A12: Police Facility Proximity and Partisanship - Robustness Checks) star(* 0.10 ** 0.05 *** 0.01) drop(*round_n) b(3) se compress replace

** Table A13. Police Facility Proximity and Partisanship - Election Security and Campaign Rallies

mixed police_election_security_45 party_id_opp enum_police $controls_ab || townvill: enum_police urbrur, vce(cluster townvill)
estimates store r5
mixed police_election_security_45 party_id_opp##enum_police $controls_ab || townvill: enum_police urbrur, vce(cluster townvill)
estimates store r6
mixed police_rallies_45 party_id_opp enum_police $controls_ab || townvill: enum_police urbrur, vce(cluster townvill)
estimates store r7
mixed police_rallies_45 party_id_opp##enum_police $controls_ab || townvill: enum_police urbrur, vce(cluster townvill)
estimates store r8

esttab r5 r6 r7 r8 using Table_A13.rtf, label mtitle(" " " " " " " ") title(Table A13: Police Facility Proximity and Partisanship - HLM Regressions) star(* 0.10 ** 0.05 *** 0.01) drop(*round_n) b(3) se compress replace

